package rad.framework.uml2.uml.edit.providers.elementItemProvider.namedElement;

import java.util.Collection;
import java.util.List;

import org.eclipse.emf.common.notify.AdapterFactory;
import org.eclipse.emf.common.notify.Notification;
import org.eclipse.emf.common.util.ResourceLocator;
import org.eclipse.emf.edit.provider.ComposeableAdapterFactory;
import org.eclipse.emf.edit.provider.IEditingDomainItemProvider;
import org.eclipse.emf.edit.provider.IItemLabelProvider;
import org.eclipse.emf.edit.provider.IItemPropertySource;
import org.eclipse.emf.edit.provider.IStructuredItemContentProvider;
import org.eclipse.emf.edit.provider.ITreeItemContentProvider;
import org.eclipse.emf.edit.provider.ItemPropertyDescriptor;
import org.eclipse.emf.edit.provider.ViewerNotification;
import org.eclipse.uml2.uml.ActivityPartition;
import org.eclipse.uml2.uml.UMLFactory;
import org.eclipse.uml2.uml.UMLPackage;

import rad.framework.uml2.uml.edit.UMLEditPlugin;

public class ActivityPartitionItemProvider
		extends NamedElementItemProvider
		implements IEditingDomainItemProvider, IStructuredItemContentProvider, ITreeItemContentProvider, IItemLabelProvider, IItemPropertySource {

	public ActivityPartitionItemProvider(AdapterFactory adapterFactory) {
		super(adapterFactory);
	}

	@Override
	public List getPropertyDescriptors(Object object) {
		if (itemPropertyDescriptors == null) {
			super.getPropertyDescriptors(object);

			addSubgroupPropertyDescriptor(object);
			addSuperGroupPropertyDescriptor(object);
			addInActivityPropertyDescriptor(object);
			addContainedEdgePropertyDescriptor(object);
			addContainedNodePropertyDescriptor(object);
			addIsDimensionPropertyDescriptor(object);
			addIsExternalPropertyDescriptor(object);
			addNodePropertyDescriptor(object);
			addSubpartitionPropertyDescriptor(object);
			addSuperPartitionPropertyDescriptor(object);
			addRepresentsPropertyDescriptor(object);
			addEdgePropertyDescriptor(object);
		}
		return itemPropertyDescriptors;
	}

	protected void addSubgroupPropertyDescriptor(Object object) {
		itemPropertyDescriptors.add(createItemPropertyDescriptor(((ComposeableAdapterFactory) adapterFactory).getRootAdapterFactory(), getResourceLocator(), getString("_UI_ActivityGroup_subgroup_feature"),
				getString("_UI_PropertyDescriptor_description", "_UI_ActivityGroup_subgroup_feature", "_UI_ActivityGroup_type"),
				UMLPackage.Literals.ACTIVITY_GROUP__SUBGROUP, false, null, null, new String[] { "org.eclipse.ui.views.properties.expert"
				}));
	}

	protected void addSuperGroupPropertyDescriptor(Object object) {
		itemPropertyDescriptors.add(createItemPropertyDescriptor(((ComposeableAdapterFactory) adapterFactory).getRootAdapterFactory(), getResourceLocator(), getString("_UI_ActivityGroup_superGroup_feature"),
				getString("_UI_PropertyDescriptor_description", "_UI_ActivityGroup_superGroup_feature", "_UI_ActivityGroup_type"),
				UMLPackage.Literals.ACTIVITY_GROUP__SUPER_GROUP, false, null, null, new String[] { "org.eclipse.ui.views.properties.expert"
				}));
	}

	protected void addInActivityPropertyDescriptor(Object object) {
		itemPropertyDescriptors.add(createItemPropertyDescriptor(((ComposeableAdapterFactory) adapterFactory).getRootAdapterFactory(), getResourceLocator(), getString("_UI_ActivityGroup_inActivity_feature"),
				getString("_UI_PropertyDescriptor_description", "_UI_ActivityGroup_inActivity_feature", "_UI_ActivityGroup_type"),
				UMLPackage.Literals.ACTIVITY_GROUP__IN_ACTIVITY, true, null, null, new String[] { "org.eclipse.ui.views.properties.expert"
				}));
	}

	protected void addContainedEdgePropertyDescriptor(Object object) {
		itemPropertyDescriptors.add(createItemPropertyDescriptor(((ComposeableAdapterFactory) adapterFactory).getRootAdapterFactory(), getResourceLocator(), getString("_UI_ActivityGroup_containedEdge_feature"),
				getString("_UI_PropertyDescriptor_description", "_UI_ActivityGroup_containedEdge_feature", "_UI_ActivityGroup_type"),
				UMLPackage.Literals.ACTIVITY_GROUP__CONTAINED_EDGE, false, null, null, new String[] { "org.eclipse.ui.views.properties.expert"
				}));
	}

	protected void addContainedNodePropertyDescriptor(Object object) {
		itemPropertyDescriptors.add(createItemPropertyDescriptor(((ComposeableAdapterFactory) adapterFactory).getRootAdapterFactory(), getResourceLocator(), getString("_UI_ActivityGroup_containedNode_feature"),
				getString("_UI_PropertyDescriptor_description", "_UI_ActivityGroup_containedNode_feature", "_UI_ActivityGroup_type"),
				UMLPackage.Literals.ACTIVITY_GROUP__CONTAINED_NODE, false, null, null, new String[] { "org.eclipse.ui.views.properties.expert"
				}));
	}

	protected void addIsDimensionPropertyDescriptor(Object object) {
		itemPropertyDescriptors.add(createItemPropertyDescriptor(((ComposeableAdapterFactory) adapterFactory).getRootAdapterFactory(), getResourceLocator(), getString("_UI_ActivityPartition_isDimension_feature"),
				getString("_UI_PropertyDescriptor_description", "_UI_ActivityPartition_isDimension_feature", "_UI_ActivityPartition_type"),
				UMLPackage.Literals.ACTIVITY_PARTITION__IS_DIMENSION, true, ItemPropertyDescriptor.BOOLEAN_VALUE_IMAGE, null, null));
	}

	protected void addIsExternalPropertyDescriptor(Object object) {
		itemPropertyDescriptors.add(createItemPropertyDescriptor(((ComposeableAdapterFactory) adapterFactory).getRootAdapterFactory(), getResourceLocator(), getString("_UI_ActivityPartition_isExternal_feature"),
				getString("_UI_PropertyDescriptor_description", "_UI_ActivityPartition_isExternal_feature", "_UI_ActivityPartition_type"),
				UMLPackage.Literals.ACTIVITY_PARTITION__IS_EXTERNAL, true, ItemPropertyDescriptor.BOOLEAN_VALUE_IMAGE, null, null));
	}

	protected void addNodePropertyDescriptor(Object object) {
		itemPropertyDescriptors.add(createItemPropertyDescriptor(((ComposeableAdapterFactory) adapterFactory).getRootAdapterFactory(), getResourceLocator(), getString("_UI_ActivityPartition_node_feature"),
				getString("_UI_PropertyDescriptor_description", "_UI_ActivityPartition_node_feature", "_UI_ActivityPartition_type"),
				UMLPackage.Literals.ACTIVITY_PARTITION__NODE, true, null, null, null));
	}

	protected void addSubpartitionPropertyDescriptor(Object object) {
		itemPropertyDescriptors.add(createItemPropertyDescriptor(((ComposeableAdapterFactory) adapterFactory).getRootAdapterFactory(), getResourceLocator(), getString("_UI_ActivityPartition_subpartition_feature"),
				getString("_UI_PropertyDescriptor_description", "_UI_ActivityPartition_subpartition_feature", "_UI_ActivityPartition_type"),
				UMLPackage.Literals.ACTIVITY_PARTITION__SUBPARTITION, true, null, null, new String[] { "org.eclipse.ui.views.properties.expert"
				}));
	}

	protected void addSuperPartitionPropertyDescriptor(Object object) {
		itemPropertyDescriptors.add(createItemPropertyDescriptor(((ComposeableAdapterFactory) adapterFactory).getRootAdapterFactory(), getResourceLocator(), getString("_UI_ActivityPartition_superPartition_feature"),
				getString("_UI_PropertyDescriptor_description", "_UI_ActivityPartition_superPartition_feature", "_UI_ActivityPartition_type"),
				UMLPackage.Literals.ACTIVITY_PARTITION__SUPER_PARTITION, true, null, null, new String[] { "org.eclipse.ui.views.properties.expert"
				}));
	}

	protected void addRepresentsPropertyDescriptor(Object object) {
		itemPropertyDescriptors.add(createItemPropertyDescriptor(((ComposeableAdapterFactory) adapterFactory).getRootAdapterFactory(), getResourceLocator(), getString("_UI_ActivityPartition_represents_feature"),
				getString("_UI_PropertyDescriptor_description", "_UI_ActivityPartition_represents_feature", "_UI_ActivityPartition_type"),
				UMLPackage.Literals.ACTIVITY_PARTITION__REPRESENTS, true, null, null, null));
	}

	protected void addEdgePropertyDescriptor(Object object) {
		itemPropertyDescriptors.add(createItemPropertyDescriptor(((ComposeableAdapterFactory) adapterFactory).getRootAdapterFactory(), getResourceLocator(), getString("_UI_ActivityPartition_edge_feature"),
				getString("_UI_PropertyDescriptor_description", "_UI_ActivityPartition_edge_feature", "_UI_ActivityPartition_type"),
				UMLPackage.Literals.ACTIVITY_PARTITION__EDGE, true, null, null, null));
	}

	@Override
	public Collection getChildrenFeatures(Object object) {
		if (childrenFeatures == null) {
			super.getChildrenFeatures(object);
			childrenFeatures.add(UMLPackage.Literals.ACTIVITY_PARTITION__SUBPARTITION);
		}
		return childrenFeatures;
	}

	@Override
	public Object getImage(Object object) {
		return overlayImage(object, getResourceLocator().getImage("full/obj16/ActivityPartition"));
	}

	@Override
	public String getText(Object object) {
		final String label = ((ActivityPartition) object).getName();
		return label == null || label.length() == 0 ? getString("_UI_ActivityPartition_type") :
				getString("_UI_ActivityPartition_type") + " " + label;
	}

	@Override
	public void notifyChanged(Notification notification) {
		updateChildren(notification);

		switch (notification.getFeatureID(ActivityPartition.class)) {
			case UMLPackage.ACTIVITY_PARTITION__IS_DIMENSION:
			case UMLPackage.ACTIVITY_PARTITION__IS_EXTERNAL:
				fireNotifyChanged(new ViewerNotification(notification, notification.getNotifier(), false, true));
				return;
			case UMLPackage.ACTIVITY_PARTITION__SUBPARTITION:
				fireNotifyChanged(new ViewerNotification(notification, notification.getNotifier(), true, false));
				return;
		}
		super.notifyChanged(notification);
	}

	@Override
	protected void collectNewChildDescriptors(Collection newChildDescriptors, Object object) {
		super.collectNewChildDescriptors(newChildDescriptors, object);

		newChildDescriptors.add(createChildParameter(UMLPackage.Literals.ACTIVITY_PARTITION__SUBPARTITION, UMLFactory.eINSTANCE.createActivityPartition()));
	}

	@Override
	public ResourceLocator getResourceLocator() {
		return UMLEditPlugin.INSTANCE;
	}

}
